package com.qzimp.fujiancuo.controller.api;

import com.qzimp.fujiancuo.entity.vo.ResultCode;
import com.qzimp.fujiancuo.entity.vo.ResultVo;
import com.qzimp.fujiancuo.exceptions.ApiException;
import com.qzimp.fujiancuo.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/files")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping("/upload")
    public ResultVo uploadFile(@RequestParam("file") MultipartFile file) {
        String fileName = fileUploadService.uploadFile(file);
        if (fileName!= null) {
            return new ResultVo(ResultCode.SUCCESS,"文件上传成功");

        }
        throw  new ApiException(ResultCode.CUSTOM_ERROR,"文件上传失败");
    }
}